package com.inews.business.web;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.inews.business.entity.Buyer;
import com.inews.business.service.BuyerService;


@Controller
@RequestMapping(value = "/user")
public class BuyerLogonController {
	
	private static final Logger logger = Logger.getLogger(BuyerLogonController.class);

	@Autowired
	private BuyerService buyerService;
	
	
	@RequestMapping(value = "logon", method = RequestMethod.POST)
	public String userLogon(Model model, Buyer buyer) {
		if(buyer.getUsername() != null && buyer.getPassword() != null){
			if(buyerService.validUser(buyer)){
				model.addAttribute("message", "登陆成功");
				model.addAttribute("urladdress", "/");
				return "share/message";
			}else{
				model.addAttribute("error", "用户名及密码错误");
			}
		}
		return "user/logon";
	}
	
//	@RequestMapping(value = "saveBuyer", method = RequestMethod.POST)
//	public String saveBuyer(Buyer buyer, Model model){
//		String username = buyer.getUsername();
//		if(buyerService.existBuyer(username)){
//			model.addAttribute("error", "该用户已存在");
//			return "user/userReg";
//		}
//		buyerService.saveBuyer(buyer);
//		model.addAttribute("message", "注册用户成功");
//		model.addAttribute("urladdress", "/");
//		return "share/message";
//	}
//	
//	
//	@RequestMapping(value = "isUserExsit", method = RequestMethod.GET)
//	public String isUserExsit(Buyer buyer, Model model){
//		String username = buyer.getUsername();
//		if(buyerService.existBuyer(username)){
//			model.addAttribute("exsit", true);
//		}
//		return "user/checkuser";
//	}
	
	
	
	
}
